'''
Author: LostPatrol_3
Date: 2023-11-04 19:26:15
LastEditors: LostPatrol_3
LastEditTime: 2023-11-04 19:26:19
Description: 
'''
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QListWidget, QPushButton

class ChatRoomWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.members = []  # 初始成员列表为空
        self.initUI()

    def initUI(self):
        # 创建列表控件
        self.list_widget = QListWidget(self)
        
        # 创建按钮，用于模拟成员列表的动态变化
        self.add_member_button = QPushButton('Add Member', self)
        self.add_member_button.clicked.connect(self.addMember)

        # 创建垂直布局管理器
        layout = QVBoxLayout()
        layout.addWidget(self.list_widget)
        layout.addWidget(self.add_member_button)

        self.setLayout(layout)
        self.setWindowTitle('Chat Room Members')

    def addMember(self):
        # 模拟成员列表的动态变化，添加新成员到列表中
        new_member = f'Member {len(self.members) + 1}'
        self.members.append(new_member)
        self.updateMemberList()

    def updateMemberList(self):
        # 更新成员列表控件的显示
        self.list_widget.clear()
        self.list_widget.addItems(self.members)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = ChatRoomWindow()
    window.show()
    sys.exit(app.exec_())
